package functions;

public class Sin extends Term {
	private Function function;

	public Sin(double coff, double exp, Function func)
	{
		this.function = func;
		this.coff = coff;
		this.expon = exp;
	}

	@Override
	public double eval(double x)
	{
		return Math.pow(coff * Math.sin(function.eval(x)), expon);
	}

	@Override
	public FunctionIF diff()
	{
		if (expon == 0)
			return new PolynTerm(1, 0);

		/* Example sin(x^2)^3 */
		Function p = (Function) function.clone();
		Cos diff = new Cos(coff, 1, p); /* cos(x^2) */

		FunctionIF d_poly = function.diff(); /* 2*x */
		return returnDerivative(diff, d_poly);
	}

	@Override
	protected Object clone()
	{
		return new Sin(coff, expon, (Function) function.clone());
	}

	@Override
	public String toString()
	{
		if(expon == 1)
			return coff+"*sin(" + function.toString() + ")";
		else
			return coff+"*sin(" + function.toString() + ")^"+expon;
			
	}
}
